@extends('admin.layouts.base')
@section('title','广告列表')
@section('pageHeader','广告列表')

@section('content')
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <h5 class="box-title">前台用户列表</h5>
                </div>
                @if (session('info'))
                    <div id="jg" class="callout callout-info">
                        <p>{{ session('info') }}</p>
                    </div>
                @endif
                <div class="box-footer">
                    <table id="data-table" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>手机号</th>
                            <th>eth</th>
                            <th>abc</th>
                            <th>直推人数</th>
                            <th>直推收益</th>
                            <th>团队人数</th>
                            <th>团队收益</th>
                            <th>签到收益</th>
                            <th>修改时间</th>
                        </tr>
                        </thead>

                        <tbody>
                        <meta name="csrf-token" content="{{ csrf_token() }}">
                        @foreach($data as $key => $item)
                            {{--{{dd($item->getUser()->phone)}}--}}

                                <td>{{ $key + 1 }}</td>
                                <td style="word-wrap:break-word;word-break:break-all">
                                    {{$item->phone }}
                                </td>
                                <td>{{ $item->total_bi }}</td>
                                <td style="color:#00a65a;">
                                    {{ $item->total }}
                                </td>
                                <td style="color:#00a65a;">
                                    {{ isset($item->getUser()-> person_number)?$item->getUser()-> person_number:0}}
                                </td>
                            <td style="color:#00a65a;">
                                {{ isset($item->getUser()-> person_income)?$item->getUser()-> person_income :0}}
                            </td>
                            <td style="color:#00a65a;">
                                {{ isset($item->getUser()-> team_number)?$item->getUser()-> team_number :0}}
                            </td>
                            <td style="color:#00a65a;">
                                {{ isset($item->getUser()-> team_income)?$item->getUser()-> team_income :0}}
                            </td>
                            <td style="color:#00a65a;">
                                {{ isset($item->getUser()-> sign_income)?$item->getUser()-> sign_income :0}}
                            </td>
                                    <td>{{ $item->updated_at }}</td>
                            </tr>
                        @endforeach

                        </tbody>

                    </table>

                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script>
        setInterval(function () {
            $("#jg").fadeOut(1000);
        }, 3000);

        window.onload = function () {

            // 设置统一ajax请求参数:csrf_token
            /*$.ajaxSetup({
             headers: {
             'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
             }
             });*/

            // logo输入框自动显示已选图片
            $("#logoInput").change(function () {
                var obj = $(this).parents();
                var img = event.target.files[0];
                var id = 'logo';

                if (!img) {
                    if ($('#' + id).length > 0) {
                        $('#' + id).remove()
                    }
                    return;
                }
                if (window.FileReader) {
                    var im = document.createElement('img');
                    im.id = id;
                    if ($('#logo').length < 1) {
                        obj.append(im);
                    }
                    ;

                    var fr = new FileReader();
                    fr.onloadend = function (e) {
                        document.getElementById(id).src = e.target.result;
                        var imgObj = $('#' + id);
                        imgObj.css({
                            'width': '100px',
                            'height': '100px',
                        })
                    };
                    fr.readAsDataURL(img);
                }
            });

            // 修改logo请求提交
            $('#logoFormSubmit').click(function () {
                var company_logo = $('input[name=company_logo]').val();
                if (!company_logo) {
                    alert('未选择任何图片!');
                    return false;
                }
                // 表单提交
                $('form[name=alterLogoForm]').submit();
            });

            // 修改公司基本设置请求提交
            $('#basicFormSubmit').click(function () {
                // 表单提交
                $('form[name=alterBasicForm]').submit();
            });

        }

        $("#data-table").DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true,
            "stateSave": true,
            "autoWidth": true,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "对不起，查询不到任何相关数据",
                "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
                "sInfoEmtpy": "找不到相关数据",
                "sInfoFiltered": "数据表中共为 _MAX_ 条记录)",
                "sProcessing": "正在加载中...", "sSearch": "搜索",
                "sUrl": "", //多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt  
                "oPaginate": {
                    "sFirst": "第一页",
                    "sPrevious": " 上一页 ",
                    "sNext": " 下一页 ",
                    "sLast": " 最后一页 "
                }
            } //多语言配置  
        });
    </script>
@endsection
